<?php
  class EmagParser
  {
    public static function parseEmag()
    {
      $urls = array(
        'http://www.emag.ro/aparate-foto-compacte',
        'http://www.emag.ro/aspiratoare-cu-apa---uscate',
      );
      
      foreach($urls as $url)
      {
          self::parseEmagPage($url);
      }
    }
    
    public static function parseEmagPage($url)
    {
      $products = array();
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $html = curl_exec($ch);
      curl_close($ch);
      
      $res = new DomDocument('1.0', 'utf8');
      $res->validateOnParse = true;
      @$res->loadHTML($html);
      
      $divs = $res->getElementsByTagName('div');
      foreach($divs as $div)
      {
        if($div->getAttribute('class') == 'col-2-prod' && $div->hasChildNodes())
        {
          var_dump($div->value);
          foreach($div->childNodes as $childNode)
          {
            if($childNode->nodeName == 'h2' && $childNode->hasChildNodes())
            {
              foreach($childNode->childNodes as $childNode2)
              {
                if($childNode2->nodeName == 'a')
                {
                  $products[] = $childNode2->getAttribute('href');
                  break;
                }
              }
            }
          }
        }
      }

      var_dump($products);
    }
  }